<?php
/**
 *         
 * #######################################################################
 *           +----------------------------------------------+
 *           | THIS FILE IS A PART OF "PHP ZONES" FRAMEWORK | 
 *           +----------------------------------------------+
 *           
 *  	THIS CODE IS PROTECTED UNDER Apache Software License
 *  	http://www.apache.org/licenses/LICENSE-2.0
 *
 * 	Simply stating :
 * 		Proprietary Software linking: Yes
 * 		Distribution of this software : Yes
 * 		Redistributing of the code with changes: You can
 * 		Compatible with GNU GPL : NO :D
 *
 * 	Feel free to change and use but don't need to share the code.
 *
 * 					
 * 	
 * ################   http://www.phpzones.com   ###############
 */

	/**	
	 * 		!!!!!! THIS DOCUMENTATION IS NOT MAINTAINED AND MAY BE OBSOLET !!!!!	
	 * 		FOR LATEST DOCUMENT PLZ REFER TO SITE: http://www.phpzones.com
	 * 
	 *  
	 * Applets are like modules. They are used to implement some functionalities
	 * and develop the application in a more modular fashion.
	 * 
	 * How to create a applet named "test"?
	 * 
	 * 1. Create a folder inside the applets directory, name it "test"
	 * 2. it must have app_test.php, the controller extending Applet and a view.php, a view file.
	 * Thats all!
	 * 
	 * How to use this applet?
	 * 
	 * 1. use Applet::insert("test",array("param"=>"value"));
	 * 2. or you can use like:
	 * 		<code>
	 * 			$app = Applet::create("test",array("param"=>"optional"));
	 * 			$app->show();
	 * 		</code>
	 * 
	 * Can I see the applet separately?
	 * 
	 * Yes, it is possible. To see only the test applet on browser, use the following url:
	 * 	http://localhost/app/test/show
	 * 
	 * optionally, you can also pass parameters like this:
	 * 	http://localhost/app/test/showparam1/val1/param2/val2
	 * 
	 * Previewing an applet in this way may result in wrong view as the css or js used in the layout
	 * are absent here.
	 * 
	 * To avoid this, you can create a file init.php inside the applets folder. You may also create another
	 * init.php file for any applet. PHPZones will include both the global(in applets folder) init.php 
	 * and local(in test folder) init.php. Then, you can add required css, js here.
	 * 
	 * Remember, init.php files are only included automatically when an applet is previewed by url;
	 */
	class Applet{
		/**
		 *  The name of the applet
		 */
		protected $appName;
		
		/**
		 * The session object
		 */
		public $session;
		
		/**
		 * The $_POST object
		 */
		public $post;
		
		/**
		 * The $_GET object
		 */
		public $get;
		
		/**
		 * The cookie
		 */
		public $cookie;
		
		/**
		 * public $locale
		 */
		public $locale;
		
		/**
		 * @param $name The name of the applet
		 */
		public function __construct($name){
			$this->appName = $name;
			$this->session = new ControllerSession();
			$this->post	= new ControllerPost();
			$this->get = new ControllerGet();
			$this->cookie = new ControllerCookie();
			$this->locale = zCurrentLocale();
		}
		
		public function show($view, $parms = array()){
			//zAppletView($this->appName,$view,$parms);
			zInclude(zAppletDir($this->appName) .'/'.$view . '.php',"view '$view.php' not found in applet '{$this->appName}'",$params);
		}
		
	}// end class
	
?>